package com.jackie.coupon.template.controller;

import com.jackie.coupon.template.api.beans.CouponTemplateInfo;
import com.jackie.coupon.template.service.CouponTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * services
 *
 * @author Jackie Hou
 * @date 2023/11/16 13:53
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/template")
public class CouponTemplateController {

    /**
     * add template
     * @param request
     * @return
     */
    @PostMapping("/addTemplate")
    public CouponTemplateInfo addTemplate(@RequestBody CouponTemplateInfo request) {
        log.info("Create coupon tempalte: data = {}", request);
        return couponTemplateService.createTemplate(request);
    }

    /**
     * clone
     * @param templateId
     * @return
     */
    @PostMapping("/cloneTemplate")
    public CouponTemplateInfo cloneTemplate(@RequestParam("id") long templateId) {
        log.info("Clone coupon template: data = {}", templateId);
        return couponTemplateService.cloneTemplate(templateId);
    }

    /**
     * get
     * @param id
     * @return
     */
    @GetMapping("/getTemplate")
    public CouponTemplateInfo getTemplate(@RequestParam("id") Long id) {
        log.info("load template, id={}", id);
        return couponTemplateService.loadTemplateInfo(id);
    }



    @Autowired
    private CouponTemplateService couponTemplateService;

    @GetMapping("/sayHello")
    public String sayHello() {
        return "hello";
    }



}
